<template>
	<view>
		<!-- 导航条 -->
		<view class="cu-custom" :style="{ height: $wanlshop.wanlsys().height + 'px' }">
			<view class="cu-bar fixed bg-blue" :style="{
					height: $wanlshop.wanlsys().height + 'px',
					paddingTop: $wanlshop.wanlsys().top + 'px',
					backgroundColor: common.appStyle.cart_nav_color ? common.appStyle.cart_nav_color : '#214a75',
					backgroundImage: 'url(' + $wanlshop.oss( common.appStyle.cart_nav_image, 0, 50, 1, 'transparent', 'png' ) + ')',
					color: common.appStyle.cart_font_color == 'light' ? '#ffffff' : '#333333'
				}">
				<view class="action" @tap="operate()">
					<text v-if="cart.operate">完成</text>
					<text v-else>管理</text>
				</view>
				<view style="font-weight: bold;" class="content" :style="{ top: $wanlshop.wanlsys().top + 'px' }">
					购物车
					<text class="text-sm" v-if="cart.cartnum">（共{{ cart.cartnum }}件宝贝）</text>
				</view>
			</view>
		</view>
		<block v-if="cart.list.length > 0">
			<!-- {{cart.list}} -->
			<view class="wanl-cart-shop radius-bock margin-bj padding-bj" v-for="(item, index) in cart.list"
				:key="index">
				<!-- 店铺选择 -->
				<!-- <view class="shop margin-bottom" @tap="onShop(item.shop_id)">
					
					<view class="text-xxl margin-right-sm" @tap.stop="shopchoose(item)">
						<text v-if="item.check" class="wlIcon-xuanze-danxuan wanl-orange"></text>
						<text v-else class="wlIcon-xuanze wanl-gray-light"></text>
					</view>
					<view class="shopname">
						<text class="wlIcon-dianpu1 margin-right-xs"></text>
						<text class="text-30">{{ item.shop_name }}</text>
					</view>
					<view class="info"><text class="wlIcon-fanhui2 margin-left-xs"></text></view>
				</view> -->
				<view class="wanl-cart-goods" v-for="(goods, keys) in item.products" :key="keys">
					<!-- 商品选择 -->
					<view class="text-xxl margin-right-sm" @tap="choose({ index: index, keys: keys })">
						<text v-if="goods.checked" class="wlIcon-xuanze-danxuan wanl-orange"></text>
						<text v-else class="wlIcon-xuanze wanl-gray-light"></text>
					</view>
					<view class="picture" @tap="onGoods(goods.good_id)">
						<image :src="$wanlshop.oss(goods.image, 100, 100, 1)" mode="aspectFill"></image>
					</view>
					<view class="content">
						<view class="text-cut-2" style="font-weight:600">
							{{ goods.title }}
						</view>
						<view class="cu-tag wanl-gray opt" @tap="SubmitData(goods.good_id,goods.id)">
							规格：<text v-if="goods.good_sku">{{ goods.good_sku }}</text>
						</view>
						<view class="flex justify-between align-center">
							<view class="text-price wanl-orange text-lg">
								{{price_format('yuan',goods.current_price)}}.{{price_format('fen',goods.current_price)}}
							</view>
							<view class="">
								<!-- <view @tap="bcsub(goods)">
									<text class="wlIcon-jian text-gray"></text>
								</view> -->
								<view style="text-align:center">
								<!-- {{goods.stock_num}} -->
									<uni-number-cart :min="1" :max="goods.stock_num" :value="goods.good_num"
										@change="changeStock" :cart="cart" :goods="goods"></uni-number-cart>
								</view>
								<!-- <view @tap="bcadd(goods)">
									<text class="wlIcon-tianjia"></text>
								</view> -->
							</view>
						</view>
					</view>
				</view>
			</view>
		</block>
		<block class="margin-bj padding-bj" v-else>
			<wanl-empty src="cart_default3x" text="哎呀，购物车空空如也！" />
			<!-- <wanl-product :dataList="likeData" /> -->
		</block>
		<!-- <uni-load-more :status="status" :content-text="contentText" /> -->
		<!-- #ifdef APP-PLUS -->
		<view style="height: 100rpx;"></view>
		<!-- #endif -->
		<view class="safeAreaBottom"></view>
		<!-- 操作栏 -->
		<view class="wanl-cart-foot fixedView solid-top edit" v-if="cart.operate">
			<view class="flex align-center" @tap="toCartchoose()">
				<view class="text-xxl">
					<text v-if="cart.status" class="wlIcon-xuanze-danxuan wanl-orange"></text>
					<text v-else class="wlIcon-xuanze wanl-gray-light"></text>
				</view>
				<view class="margin-left-sm">
					<text>{{ cart.status ? '取消' : '全选' }}</text>
				</view>
			</view>
			<view class="flex">
				<!-- <button v-if="cart.allnum == 0" class="cu-btn round line-gray">移动关注</button>
				<button v-else class="cu-btn round line-orange" @tap="move()">移动关注</button> -->
				<!-- <button class="cu-btn round line-orange" @tap="toEmpty()">快速清理</button> -->
				<button v-if="cart.allnum == 0" class="cu-btn round line-gray">删除</button>
				<button v-else class="cu-btn round bg-gradual-orange" @tap="del()">删除</button>
			</view>
		</view>
		<view class="wanl-cart-foot fixedView solid-top account" v-else>
			<view class="flex align-center" @tap="toCartchoose()">
				<view class="text-xxl">
					<text v-if="cart.status" class="wlIcon-xuanze-danxuan wanl-orange"></text>
					<text v-else class="wlIcon-xuanze wanl-gray-light"></text>
				</view>
				<view class="margin-left-sm text-bold">
					<text>{{ cart.status ? '取消' : '全选' }}</text>
				</view>
			</view>
			<view class="flex">
				<view class="text-sm text-right" v-if="cart.allsum">
					<view>
						合计：
						<text class="text-price wanl-orange text-lg">{{ cart.allsum }}</text>
					</view>
					<view>不含运费</view>
				</view>
				<button v-if="cart.allnum == 0" class="cu-btn round line-gray text-bold">去结算</button>
				<button v-else class="cu-btn round bg-gradual-orange" @tap="settlement()">
					去结算 <text v-if="cart.allnum">({{ cart.allnum }})</text>
				</button>
			</view>
		</view>

		<!-- 规格 -->
		<view class="cu-modal bottom-modal" :class="modalName == 'option' ? 'show' : ''" @tap="hideModal">

			<view class="cu-dialog" @tap.stop="" v-if="goodSku.good_sku">
				<view class="option wanl-modal">
					<view class="head text-left padding-bj solid-bottom">
						<view class="cu-avatar radius-bock margin-right" v-if="goodSku.good_sku.length>0"
							:style="{ backgroundImage: 'url(' + $wanlshop.oss(goodsData.img[0], 100, 100) + ')' }">
						</view>
						<view class="cu-avatar radius-bock margin-right" v-else
							:style="{ backgroundImage: 'url(' + $wanlshop.oss(goodsData.cover, 100, 100) + ')' }">
						</view>
						<view>
							<view class=" wanl-orange margin-right-xs">
								<text class='wanl-blue' style="margin-right:10px;">
									零售价: <text class="text-price">
										<text class="text-xl">
											{{ selectshop.price || goodsData.current_price}}
										</text>/{{goodsData.unit_name}}
									</text>
								</text>
							</view>
							<view class=" wanl-orange margin-right-xs">

								会员价:<text class='text-price'>
									<text class="text-xl">
										{{ selectshop.vip_price || goodsData.vip_price}}
									</text>/{{goodsData.unit_name}}
								</text>
							</view>

							<view v-if="selectArr.join('')" class="wanl-gray margin-bottom-xs">
								库存 <text class="margin-lr-xs">{{selectNum}} {{goodsData.unit_name}}</text>
							</view>
							<view class="text-sm">
								<view v-if="selectArr.join('')">
									<text class="margin-right-bj">已选择</text>
									<text class="margin-right-xs"
										v-for="(name, key) in selectArr">{{ $base64.decode(name)  }}</text>
								</view>
								<view v-else>
									请选择：
									<text class="wanl-gray-light" v-for="(item, index) in goodsData.good_sku_view"
										:key="index">
										<block v-if="index != 0">-</block>
										{{ item }}
									</text>
								</view>
							</view>
						</view>

						<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
					</view>
					<!-- 1.0.8升级 -->
					<scroll-view scroll-y="true" :style="{maxHeight: wanlsys.screenHeight / 2 + 'px'}">
						<view class="opt text-left padding-bj solid-bottom" v-for="(value, spukey) in goodSku.good_attr"
							:key="spukey">
							<view class="text-df">{{ value.name }}</view>
							<view class="tag">
								<view class="cu-tag text-sm" v-for="(item, index) in value.item" :key="index"
									:class="[item.ishow ? '' : 'noactive', subIndex[spukey] == index ? 'active' : '']"
									@tap="skuClick(item, spukey, $event, index)">
									{{ $base64.decode(item.name) }}
								</view>
							</view>
						</view>
						<view class="number padding-bj" v-if="single_price>0">
							<view class="text-df">单价
							</view>
							<view>
								{{single_price}}元<span v-if="goodsData.unit_name">/{{goodsData.unit_name}}</span>
							</view>
						</view>
						<view class="number padding-bj" v-if="price>0">
							<view class="text-df">总价
							</view>
							<view>
								{{price}}元
							</view>
						</view>
						<view class="number padding-bj">
							<view class="text-df">购买数量</view>
							<uni-number-box :min="1" :max="selectshop.stock" :value="selectNum" :disabled="canCount"
								@change="changeNum"></uni-number-box>
						</view>
					</scroll-view>

					<view class="foot padding-lr-bj">
						<button class="cu-btn bg-gradual-orange round text-bold complete"
							@tap="completeSelection(goodsData)">完成</button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex';

	export default {
		data() {
			return {
				cart_id: 0,
				is_vip: 0,
				// price:0,
				shopItemInfo: {},
				isChoice: '', // 是否从选择进入
				scrollAnimation: 100, //分享滚动
				selectNum: 1, //选中数量
				// unit_name: '',
				// pic: '',
				single_price: 0,
				current_price: 0,
				selectshop: {},
				subIndex: [],
				wanlsys: {},
				selectArr: [],
				// pic: '',
				goodsData: {},
				goodSku: {},
				modalName: null, // 弹出层
				reload: true,
				likeData: [],
				current_page: 1, //当前页码
				last_page: 1, //总页码
				status: 'loading',
				contentText: {
					contentdown: '',
					contentrefresh: '正在加载...',
					contentnomore: ''
				}
			};
		},
		onReachBottom() {
			//判断是否最后一页
			if (this.current_page >= this.last_page) {
				this.status = 'noMore';
			} else {
				this.reload = false;
				this.current_page = this.current_page + 1; //页码+1
				this.status = 'loading';
				this.loadlikeData();
			}
		},
		watch: {
			selectshop: {
				immediate: true, // 初始化立即执行
				handler(newVal, oldVal) {
					// alert(JSON.stringify(this.selectshop)) 
				}
			}
		},
		computed: {
			...mapState(['cart', 'common']),
			canCount() {
				console.log(this.subIndex)
				return this.subIndex.some(item => item === -1);
			},
			unit_name: function() {
				let unit_name = '';
				let name = '';
				if (this.selectshop && this.selectshop.good_sku) {
					name = this.selectshop.good_sku;
				} else if (this.goodsData.good_sku_view) {
					name = this.goodsData.good_sku_view.join('|');
				}
				console.log(name)
				//二〇二一年八月二十二日 07:21:28
				if (this.goodsData && this.goodsData.unit_name) {
					unit_name = this.goodsData.unit_name
				}

				if (this.goodSku && this.goodSku.good_attr) {
					this.goodSku.good_attr.forEach(function(el) {
						// console.log(JSON.stringify(el))
						if (el.name == '包装规格' || el.name == '计价单位') {
							el.sub.forEach(function(elm) {
								// console.log(JSON.stringify(elm))
								if (name.indexOf(elm) != -1) {
									unit_name = elm;
								}

							})
						}
					});
					console.log(unit_name)
				}
				return unit_name;
			},
			pic: function() {
				let that = this;
				let pic = '';
				let name = '';
				if (this.selectshop && this.selectshop.good_sku) {
					name = this.selectshop.good_sku;
				} else if (this.goodsData.good_sku_view) {
					name = this.goodsData.good_sku_view.join('|');
				}
				// alert(name)
				if (this.goodSku && this.goodSku.good_sku) {
					this.goodSku.good_sku.forEach(function(el) {
						if (name === el.good_sku) {
							// alert(el.cover)
							if (el.stock_num) {
								// console.log(999)
								pic = el.cover;
							} else {
								pic = that.goodsData.img[0]
							}

						}
						// else {
						// 	pic = this.goodsData.img[0]
						// }
					})
				}

				// console.log(pic)
				return pic;
			},
			kucun: function() {
				let that = this;
				var kucun = false;
				let name = ''
				if (!this.goodsData.good_sku_view) {
					return this.goodsData.stock_num;
				}

				// alert(this.goodSku.good_attr.length)


				if (this.goodsData.good_sku_view && this.goodSku.good_attr && this.goodsData.good_sku_view.length !=
					this.goodSku.good_attr.length) {
					this.selectNum = 0

					return;
				}

				if (this.selectshop && this.selectshop.good_sku) {
					name = this.selectshop.good_sku;
				} else if (this.goodsData.good_sku_view) {
					name = this.goodsData.good_sku_view.join('|');
				}


				if (this.goodSku && this.goodSku.good_sku) {
					this.goodSku.good_sku.forEach(function(el) {
						if (name === el.good_sku) {
							if (el.stock_num > 0) {
								kucun = el.stock_num;

								that.count = 1
							} else {
								kucun = 0
								that.count = 0
							}
						}
					})
				}

				if (!kucun) {
					kucun = 0;
					that.count = 0
				}
				// alert(kucun)
				return kucun;
			},

			price: function() {

				let that = this;

				if (this.is_vip == 1 && this.goodsData.vip_price > 0) { //2022年3月15日07:25:06
					var price = this.goodsData.vip_price;
					this.single_price = this.goodsData.vip_price;

					this.vip_price = this.goodsData.vip_price;
					this.current_price = this.goodsData.current_price;

				} else {
					var price = this.goodsData.current_price;
					this.single_price = this.goodsData.current_price;

					this.vip_price = this.goodsData.vip_price;
					this.current_price = this.goodsData.current_price;
				}



				// alert(JSON.stringify(this.current_price))
				if (this.selectshop.good_sku && this.goodSku.good_sku) {
					var name = this.selectshop.good_sku;
					this.goodSku.good_sku.forEach(function(el) {
						console.log(666)
						console.log(name)
						console.log(el.good_sku)
						if (name === el.good_sku) {
							// this.sku_id = el.sku_id;
							// alert(JSON.stringify(el.price,null,2))
							// if (el.stock_num) { //2022年3月28日22:13:12
							if (that.is_vip == 1 && el.vip_price > 0) {
								price = el.vip_price;

								that.vip_price = el.vip_price;
								that.current_price = el.price;
							} else {
								price = el.price;
								that.vip_price = el.vip_price;
								that.current_price = el.price;
							}
							console.log(87)
							console.log(price)
							// this.current_price = el.price
							that.single_price = price.toFixed(2);
							// } else {}
						}

						// console.log(this.sku_id)
					})
				}

				if (!uni.getStorageSync("wanlshop:user").token) {
					var price = this.goodsData.current_price;
					this.single_price = this.goodsData.current_price;

					this.vip_price = this.goodsData.vip_price;
					this.current_price = this.goodsData.current_price;
				}

				// alert(name)

				// alert(this.current_price)
				// this.selectNum = this.selectNum > 0 ? this.selectNum : 1;
				// console.log(price)
				if (this.selectNum > 0) {
					return (price * this.selectNum).toFixed(2);
				} else {
					return (price * 1).toFixed(2);
				}

			},
			getCarnum: function() {
				uni.request({
					url: '/api/GoodCart/xcx_goodCartCount',
					data: {
						token: uni.getStorageSync("wanlshop:user").token,
					},
					success: res => {
						console.log(res)

					}
				});
			},

		},

		onShow() {
			setTimeout(() => {
				uni.setNavigationBarColor({
					frontColor: this.$store.state.common.appStyle.cart_font_color == 'light' ?
						'#ffffff' : '#000000',
					backgroundColor: '#214a75'
				});
			}, 200);
			// 监听选择自提点
			// uni.$once("SELECT_STORE", (res) => {
			// 	this.storeInfo = JSON.parse(res.storeInfo);
			// });
			this.$store.dispatch('cart/login');
		},
		onLoad() {
			this.wanlsys = this.$wanlshop.wanlsys();
			// window.location.reload()
			// 加载猜你喜欢
			// this.loadlikeData();
			// this.get_list(2067)
			// this.loadData(2067)
			this.$store.dispatch('cart/login');
		},
		methods: {
			...mapActions({
				login: 'cart/login',
				operate: 'cart/operate', // 管理购物车
				choose: 'cart/choose', // 选择商品
				shopchoose: 'cart/shopchoose', // 选择店铺
				cartchange: 'cart/cartchange',
				bcadd: 'cart/bcadd', // 添加数量
				bcsub: 'cart/bcsub', // 减少数量
				move: 'cart/move', // 移动购物车
				settlement: 'cart/settlement', // 结算购物车
				del: 'cart/del' // 删除选中购物车
			}),
			// 完成选择
			completeSelection(goodsData) {
				// alert(this.selectNum)
				// alert(JSON.stringify(this.selectshop))
				let goods = {
					cart_id: this.cart_id,
					shop_id: goodsData.shop_id,
					// shop_name: goodsData.shop.shopname,
					id: goodsData.id,
					good_id: goodsData.good_id,
					title: goodsData.title,
					good_num: this.selectNum,
					image: goodsData.cover,
					sku: this.selectshop,
					sku_id: this.selectshop.id,
					current_price: this.selectshop.price * 100 / this.selectNum,
					good_sku: this.selectshop.good_sku,
					peisong_type_id: goodsData.peisong_type_id,
					peisong_type_name: goodsData.peisong_type_name,
					sum: this.$wanlshop.bcmul(this.selectshop.price * 100, this.selectNum)
				};

				// this.$store.dispatch('cart/bcadd', goods);
				this.$store.dispatch('cart/edit', goods);


				this.$wanlshop.msg('已更新购物车');
				this.hideModal();
				this.reload = true;
				// window.location.reload()
				// this.selectshop = {}
				// this.loadData(goodsData.id)
				// this.get_list(goodsData.id)
				// this.modalName = null;
			},
			// 提交数据
			SubmitData(id, cart_id) {
				this.selectArr = []
				console.log(id)
				this.cart_id = cart_id;

				this.get_list(id)
				this.loadData(id)


				// if (this.canCount) {
				// 	this.$wanlshop.msg('请选择完成规格');
				// } else {
				// 	// this.isChoice = name;
				// 	// this.ProcessingData();
				// 	//更新购物车
				// }
			},
			// 弹出层
			showModal(name) {
				this.isChoice = '';
				// 滚动下分享
				if (name == 'share' && this.modalName != 'share') {
					setTimeout(() => {
						this.scrollAnimation = 0;
					}, 300);
				}
				this.modalName = name;
			},
			// 关闭弹出层
			hideModal(name) {
				if (name) {
					this.showModal(name);
				} else {
					this.modalName = null;
				}
			},
			Stringdecode(str) {
				str = this.$base64.decode(str.replace(/\s/g, '+'));
				return str;
			},
			// 商品规格组合 选择
			skuClick(value, spukey, event, index) {
				// alert(JSON.stringify(value))
				// alert(JSON.stringify(spukey))
				if (value.ishow) {
					if (this.selectArr[spukey] != value.name) {

						this.$set(this.selectArr, spukey, value.name);
						this.$set(this.subIndex, spukey, index);
					} else {
						this.$set(this.selectArr, spukey, '');
						this.$set(this.subIndex, spukey, -1);
					}
					console.log(this.selectArr)
					console.log(this.subIndex)
					this.checkInpath(spukey);
					//如果全部选完
					console.log(this.shopItemInfo)
					if (this.selectArr.every(item => item != '')) {
						this.selectshop = this.shopItemInfo[this.selectArr];
						console.log(this.selectshop)
						// 1.1.3升级
						this.selectshop.difference.map((name, index, arr) => {
							arr[index] = this.Stringdecode(name)
						})
						// this.loadStock(this.selectshop.id);
						this.selectNum = 1;

					}
				}
			},
			//循环所有属性判断哪些属性可选
			checkInpath(clickIndex) {
				if (this.goodSku.good_attr) {
					//当前选中的兄弟节点和已选中属性不需要循环
					for (let i = 0, len = this.goodSku.good_attr.length; i < len; i++) {
						if (i == clickIndex) {
							continue;
						}
						let len2 = this.goodSku.good_attr[i].item.length;
						for (let j = 0; j < len2; j++) {
							if (this.subIndex[i] != -1 && j == this.subIndex[i]) {
								continue;
							}
							let choosed_copy = [...this.selectArr];
							console.log(888)
							console.log(this.goodSku.good_attr[i].item[j].name)
							this.$set(choosed_copy, i, this.goodSku.good_attr[i].item[j].name);
							let choosed_copy2 = choosed_copy.filter(item => item !== '' && typeof item !== 'undefined');
							if (this.shopItemInfo.hasOwnProperty(choosed_copy2)) {
								console.log(6789)
								console.log(this.goodSku.good_attr[i])
								this.$set(this.goodSku.good_attr[i].item[j], 'ishow', true);
							} else {
								this.$set(this.goodSku.good_attr[i].item[j], 'ishow', false);
							}
						}
					}
					console.log(7890)
				}

				// console.log(this.goodsData.spu)
			},
			//计算有多小种可选路径
			checkItem() {
				if (this.goodSku.good_sku) {
					let result = this.goodSku.good_sku.reduce(
						(arrs, items) => {
							return arrs.concat(
								items.difference.reduce(
									(arr, item) => {
										return arr.concat(
											arr.map(item2 => {

												//利用对象属性的唯一性实现二维数组去重
												if (!this.shopItemInfo.hasOwnProperty([...item2, item])) {
													// alert(item2)

													this.shopItemInfo[[...item2, item]] = items;
												}

												return [...item2, item];
											})
										);
									},
									[
										[]
									]
								)
							);
						},
						[
							[]
						]
					);
					console.log(7890)
					console.log(this.shopItemInfo)
				}

			},
			//商品规格修改数量
			async changeStock(val, goods,cart) {
				console.log(111)
				// console.log(JSON.stringify(cart))
    //             alert(goods.good_num)
				// alert(val)
				goods.good_num = Number(val);
				goods.sum = this.$wanlshop.bcmul(goods.current_price, goods.good_num)
				console.log(JSON.stringify(goods))
				await uni.request({
					url: '/api/GoodCart/editGoodCart',
					method: 'POST',
					data: {
						good_cart_id: goods.id,
						token: uni.getStorageSync("wanlshop:user").token,
						// good_cart_id: goods.id,
						good_num: goods.good_num,
						good_sku: goods.good_sku
					},
					success: res => {
						// console.log(JSON.stringify(cart))
						let allnum=0;
						let allsum=0;
						cart.list.forEach((cart1, index) => {
							console.log(cart1)
							cart1.products.forEach((goods, key) => {
								
								console.log(goods)
								if (goods.checked) {
									  // alert(cart.allnum)
									  allsum += goods.sum;
									  allnum += goods.good_num;
									}
								})
							});
						cart.allsum = allsum;
						cart.allnum = allnum;
						// alert(goods.sum)
						// cart.allsum = this.$wanlshop.bcadd(cart.allsum, goods.sum);
						// cart.allnum += goods.good_num;
						console.log(cart.allnum)
						// dispatch('login');
						// if (type == 'follow') {
						// rootState.statistics.dynamic.collection = rootState.statistics.dynamic
						// 	.collection + res.data;
						//}
						// dispatch('format', goods);
					}
				});
				// this.$store.dispatch('cart/choosetrue');
				// this.reload = true;
			},
			//商品规格修改数量
			changeNum(val) {

				if (this.selectshop.stock_num) {
					let num = parseInt(val);
					if (num > this.selectshop.stock_num) {
						this.$wanlshop.msg(`数量不能超过库存 ${this.selectshop.stock_num} 件`);
						this.selectNum = parseInt(this.selectshop.stock_num);
					} else {
						this.selectNum = parseInt(val);
					}
				}
				console.log(this.selectNum)
			},
			async loadData(good_id) {
				//加载商品
				await uni.request({
					url: '/api/Good/goodDetails',
					data: {
						good_id: good_id,
						token: uni.getStorageSync("wanlshop:user").token
					},
					success: res => {
						console.log(res.data)
						//详情正则
						this.goodsData = res.data;

						this.modalName = 'option';

						// 计算锚点高度
						setTimeout(() => {
							// this.calcAnchor();
						}, 1000);
					}
				});
			},
			async get_list(good_id) {
				// alert(this.type)

				await uni.request({
					url: '/api/Good/goodSku',
					data: {
						good_id: good_id,
						is_tuan: 0,
						type: 'good',
						token: uni.getStorageSync("wanlshop:user").token
					},
					success: res => {
						console.log(res)
						this.goodSku = res.data
						this.is_vip = res.data.is_vip

						// 商品规格组合
						if (this.goodSku.good_attr) {
							this.goodSku.good_attr.map((item, index) => {


								// 1.1.3升级
								item.item.map((name, key, arr) => {

									arr[key].name = this.$base64.encode(arr[key].name)

								});
								// this.$set(this.goodSku.good_attr[index+1].item[0], 'ishow',
								// 	true);
								// this.selectArr.push('');
								// this.subIndex.push(-1);

							});
							// console.log(console.log(item))
						}
						console.log(789)
						// alert(JSON.stringify(this.goodSku.good_attr));

						if (this.goodSku.good_sku) {
							// 1.1.3升级
							this.goodSku.good_sku.map(item => {
								item.difference.map((name, index, arr) => {
									arr[index] = this.$base64.encode(name)
								});
							});
						}

						console.log(789)
						// alert(JSON.stringify(this.goodSku.good_sku));
						console.log(this.goodSku.good_sku);

						//    console.log(this.goodSku.good_sku);
						this.checkItem(); //计算sku里面规格形成路径
						this.checkInpath(-1); //传-1是为了不跳过循环

						if (this.goodSku.good_attr) {
							this.goodSku.good_attr.map((item, index) => {
								// this.skuClick(item.item, index, $event, index)
								if (item.item) {
									this.$set(this.selectArr, index, item.item[0].name);
								}

								this.$set(this.subIndex, index, 0);
								this.checkInpath(index);

								// alert(JSON.stringify(this.selectArr))

								console.log(this.goodSku.good_attr[index])

								// alert(JSON.stringify(this.goodSku.good_attr[1].item[0]))
								this.$set(this.goodSku.good_attr[index].item[0], 'ishow',
									true);

								if (this.selectArr.every(item => item != '')) {
									this.selectshop = this.shopItemInfo[this.selectArr];

									// 1.1.3升级
									// this.selectshop.difference.map((name, index, arr) => {
									// 	arr[index] = this.$base64.decode(name)
									// })
									// this.loadStock(this.selectshop.id);
									this.selectNum = 1;

								}
								console.log(this.selectshop)
							});
						}

					}
				});

			},
			price_format: function(type, price) {
				// var price = price / 100;
				var status = (price + '').indexOf('.')
				if (status == '-1') {
					if (type == 'yuan') {
						return price;
					}
					if (type == 'fen') {
						return '00';
					}
				}
				var price_array = (price + '').split('.')
				if (type == 'yuan') {
					return price_array[0];
				}
				if (type == 'fen') {
					var price_fen = price_array[1].length < 2 ? price_array[1] + '0' : price_array[1];
					return price_fen;
				}
			},
			async loadlikeData() {
				await uni.request({
					url: '/wanlshop/product/likes?pages=cart',
					data: {
						page: this.current_page
					},
					success: res => {
						this.likeData = this.reload ? res.data.data : this.likeData.concat(res.data
							.data); //评论数据 追加
						this.current_page = res.data.current_page; //当前页码
						this.last_page = res.data.last_page; //总页码
						this.status = 'more';
					}
				});
			},
			// 禁止空购物车点击全选
			toCartchoose() {
				if (this.$store.state.cart.list.length == 0) {
					uni.showModal({
						content: '购物车没有任何宝贝，马上去选一个心仪的宝贝吧~',
						success: res => {
							if (res.confirm) {
								this.$wanlshop.on('/pages/category');
							}
						}
					});
				} else {
					this.$store.dispatch('cart/cartchoose');
				}
			},
			toEmpty() {
				uni.showModal({
					content: '是否从购物车中清除该商品？',
					success: res => {
						if (res.confirm) {
							this.$store.dispatch('cart/del');
						}
					}
				});
			}
		}
	};
</script>

<style>
	.cu-modal {
		z-index: 99999
	}

	.wanl-gray-light {
		color: #eee;
	}

	.wanl-cart-shop {
		background-color: #ffffff;
	}

	/* #ifndef MP-ALIPAY */
	.wanl-cart-shop radio::before,
	.wanl-cart-shop checkbox::before {
		margin-top: -7px;
		right: 1px;
	}

	.wanl-cart-shop radio .wx-radio-input,
	.wanl-cart-shop checkbox .wx-checkbox-input,
	.wanl-cart-shop radio .uni-radio-input,
	.wanl-cart-shop checkbox .uni-checkbox-input {
		margin: 0;
		width: 16px;
		height: 16px;
	}

	/* #endif */
	.wanl-cart-shop checkbox-group {
		margin-right: 25rpx;
	}

	.wanl-cart-shop .shop {
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.wanl-cart-shop .shop .shopname {
		position: absolute;
		display: flex;
		align-items: center;
		left: 60rpx;
	}

	.wanl-cart-shop .shop uni-checkbox .uni-checkbox-input {
		border: 1px solid #cccccc;
	}

	/* 商品 */
	.wanl-cart-goods {
		display: flex;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.wanl-cart-goods:last-child {
		margin-bottom: 18rpx;
	}

	.wanl-cart-goods .picture {
		width: 180rpx;
		height: 180rpx;
	}

	.wanl-cart-goods .picture image {
		width: 180rpx;
		height: 180rpx;
		overflow: hidden;
		border-radius: 20rpx;
	}

	/* 1.0.6升级 */
	.wanl-cart-goods .content {
		padding-left: 25rpx;
		width: 100%;
		overflow: hidden;
	}

	.wanl-cart-goods .content .opt {
		font-size: 24rpx;
		padding: 0;
		color: #000000;
		height: 32rpx;
		background-color: #f6f6f6;
		font-weight: 300;
		margin-top: 10rpx;
		margin-bottom: 25rpx;
		border-radius: 4rpx;
	}

	.wanl-cart-goods .content .opt text {
		padding-right: 6rpx;
		padding-left: 10rpx;
	}

	/* 操作条 */
	.wanl-cart-foot {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		z-index: 997;
		min-height: 52px;
		background-color: #ffffff;
		padding: 0 25rpx;
	}

	.wanl-cart-foot.solid:after {}

	/* #ifndef MP-ALIPAY */
	.wanl-cart-foot radio:before,
	.wanl-cart-foot checkbox:before {
		margin-top: -7px;
		right: 1px;
	}

	.wanl-cart-foot radio .wx-radio-input,
	.wanl-cart-foot checkbox .wx-checkbox-input,
	.wanl-cart-foot radio .uni-radio-input,
	.wanl-cart-foot checkbox .uni-checkbox-input {
		margin: 0;
		width: 16px;
		height: 16px;
	}

	/* #endif */
	.wanl-cart-foot.account button {
		margin-left: 25rpx;
	}

	.wanl-cart-foot.edit button {
		margin-left: 20rpx;
	}

	.wanl-cart-foot.account .cu-btn {
		padding: 0 25rpx;
		font-size: 32rpx;
		height: 72rpx;
		margin-top: 6rpx;
		/* border-radius: 20rpx; */
	}

	.wanl-cart-foot.edit .cu-btn {
		padding: 0 30rpx;
		font-size: 24rpx;
		height: 56rpx;
	}
</style>